﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.CMS.TemplateLanguage.Properties;
using MethodWorx.CMS.TemplateLanguage.Design;

namespace MethodWorx.CMS.TemplateLanguage.Parsers
{
    public class StringOutput : IParser, IDesignable
    {
        [Property]
        public string Tag { get; set; }

        public object Parse(Web.CmsRequestContext context, IEnumerable<object> stack, Dictionary<string, object> parameters)
        {
            if (!string.IsNullOrEmpty(this.Tag))
                return "<" + this.Tag + ">" + stack.First().ToString() + "</" + this.Tag + ">";
            else
                return stack.First().ToString();
        }

        public string Name
        {
            get { return "out"; }
        }

        public string Namespace
        {
            get { return "string"; }
        }

        public string[] Parameters
        {
            get { return new string[] { }; }
        }

        public void Design(IDesigner designer)
        {
            if (!string.IsNullOrEmpty(this.Tag))
            {
                designer.AddControl("String:Output")
                    .AddContentBeforeChildren("&lt;" + this.Tag + "&gt; Output")
                    .SetControlType(DesignerControlType.Label);
            }
            else
            {
                designer.AddControl("String:Output")
                    .AddContentBeforeChildren("Standard Output")
                    .SetControlType(DesignerControlType.Label);
            }
        }
    }
}
